﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QL_NOI_TRU
{
    public partial class frmNhapTTPhauThuat : DevExpress.XtraEditors.XtraForm
    {
        public frmNhapTTPhauThuat()
        {
            InitializeComponent();
        }

        private void frmNhapTTPhauThuat_Load(object sender, EventArgs e)
        {
            //do du lieu vao grid
            var kn = new Ketnoi(frmDangnhap.stringConn);
            gridControl1.DataSource = kn.ExcuteQuery("select MAPHIEU as 'Mã phiếu điều trị',MAPT as 'Mã loại phẫu thuật',MAPHONGPT as 'Mã phòng phẫu thuật',NGAYPT as 'Ngày phẫu thuật',GIO as 'Giờ phẫu thuật',EKIPPT as 'EKIP phẫu thuật',KETQUA as 'Kết quả' from LICH_PHAU_THUAT");
        
            //do du lieu vao cbbmaPhieudieutri
            var maDV = "select PHIEU_DIEU_TRI.MAPHIEU,BENH_NHAN.HOTEN from PHIEU_DIEU_TRI,BENH_NHAN,BENH_AN where PHIEU_DIEU_TRI.MABENHAN = BENH_AN.MABENHAN and BENH_AN.MA_BN = BENH_NHAN.MA_BN ";
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cm = conn.CreateCommand();
            cm.CommandText = maDV;
            conn.Open();
            SqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                var newVariable = cbbPhieuDieuTri.Properties.Items.Add(String.Format("{0} | {1}", dr["MAPHIEU"], dr["HOTEN"]));
            }
            dr.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var f = new frmCapNhatloaiPhauThuat();
            f.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var f = new frmCapNhatDSPhongPhauThuat();
            f.Show();
        }

        private void cbbPhieuDieuTri_SelectedIndexChanged(object sender, EventArgs e)
        {
            var maDV = "select * from LOAI_PHAU_THUAT ";
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cm = conn.CreateCommand();
            cm.CommandText = maDV;
            conn.Open();
            SqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                var newVariable = cbbLoaiPhauThuat.Properties.Items.Add(String.Format("{0} | {1} | {2}", dr["MAPT"], dr["MOTA"],dr["CHIPHI"]));
            }
        }

        private void cbbLoaiPhauThuat_SelectedIndexChanged(object sender, EventArgs e)
        {
            var maDV = "select * from PHONGPHAUTHUAT ";
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cm = conn.CreateCommand();
            cm.CommandText = maDV;
            conn.Open();
            SqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                var newVariable = cbbPhongPT.Properties.Items.Add(String.Format("{0} | {1}", dr["MAPHONGPT"], dr["TENPHONGPT"]));
            }
        }

        private void cbbPhieuDieuTri_KeyPress(object sender, KeyPressEventArgs e)
        {
            cbbLoaiPhauThuat.Focus();
        }

    }
}